package cn.dada.dadarecipes.mall.productreview.service.Impl;

import cn.dada.dadarecipes.mall.productreview.mapper.ProductReviewMapper;
import cn.dada.dadarecipes.mall.productreview.pojo.dto.AddCommentParam;
import cn.dada.dadarecipes.mall.productreview.pojo.entity.ProductReview;
import cn.dada.dadarecipes.mall.productreview.pojo.vo.ProductReviewVO;
import cn.dada.dadarecipes.mall.productreview.service.ProductReviewService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class ProductReviewServiceImpl implements ProductReviewService {

    @Autowired
    ProductReviewMapper productReviewMapper;
    @Override
    public List<ProductReviewVO> selectComment(Long productId) {
        log.debug("商品评价查询业务:{}", productId);
        List<ProductReviewVO> productReviewVOList = productReviewMapper.selectComment(productId);
        return productReviewVOList;
    }

    @Override
    public void addComment(AddCommentParam addCommentParam) {
        log.debug("新增评论业务:{}", addCommentParam);
        ProductReview productReview = new ProductReview();
        BeanUtils.copyProperties(addCommentParam, productReview);
        productReview.setReviewDate(new Date());
        productReviewMapper.insert(productReview);
    }

    @Override
    public void deleteComment(Long id) {
        log.debug("删除评论业务:{}", id);
        productReviewMapper.delete(id);
    }
}
